package com.xs.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xs.common.annotation.Log;
import com.xs.common.core.controller.BaseController;
import com.xs.common.core.domain.AjaxResult;
import com.xs.common.enums.BusinessType;
import com.xs.business.domain.TOrderFrom;
import com.xs.business.service.ITOrderFromService;
import com.xs.common.utils.poi.ExcelUtil;
import com.xs.common.core.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2024-06-30
 */
@RestController
@RequestMapping("/business/order")
public class TOrderFromController extends BaseController
{
    @Autowired
    private ITOrderFromService tOrderFromService;

    /**
     * 查询订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TOrderFrom tOrderFrom)
    {
        startPage();
        List<TOrderFrom> list = tOrderFromService.selectTOrderFromList(tOrderFrom);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOrderFrom tOrderFrom)
    {
        List<TOrderFrom> list = tOrderFromService.selectTOrderFromList(tOrderFrom);
        ExcelUtil<TOrderFrom> util = new ExcelUtil<TOrderFrom>(TOrderFrom.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tOrderFromService.selectTOrderFromById(id));
    }

    /**
     * 新增订单
     */
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOrderFrom tOrderFrom)
    {
        return toAjax(tOrderFromService.insertTOrderFrom(tOrderFrom));
    }

    /**
     * 修改订单
     */
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOrderFrom tOrderFrom)
    {
        return toAjax(tOrderFromService.updateTOrderFrom(tOrderFrom));
    }

    /**
     * 删除订单
     */
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tOrderFromService.deleteTOrderFromByIds(ids));
    }
}
